﻿<template>
	<el-container>
		<!-- <el-aside width="250px" v-loading="showGrouploading" v-if="isShow">
			<el-container>
				<el-main class="nopadding">
					<el-tree
						ref="tree"
						class="menu"
						node-key="id"
						:data="group"
						:current-node-key="''"
						:highlight-current="true"
						:expand-on-click-node="false"
						default-expand-all="true"
						:filter-node-method="groupFilterNode"
						@node-click="groupClick"
					></el-tree>
				</el-main>
			</el-container>
		</el-aside> -->
		<el-container>
			<el-header>
				<div class="left-panel">
					<el-button
						type="success"
						icon="el-icon-plus"
						:disabled="!addState"
						@click="opAdd"
					></el-button>
					<el-button
						type="primary"
						icon="el-icon-edit"
						:disabled="!editBatchState"
						@click="opBatchEdit"
					></el-button>
					<el-button
						type="danger"
						plain
						icon="el-icon-delete"
						:disabled="!deleteBatchState"
						@click="opBatchDelete"
					></el-button>
				</div>
				<div class="right-panel">
					<el-button
						:icon="Search"
						 
						type="primary"
						@click="opBindData"
					>
						查询
					</el-button>
					<el-button
						:icon="Search"
						type="info"
						plain
						@click="resetSearch"
					>
						重置
					</el-button>
					<el-button
						text
						type="primary"
						@click="showCondition = !showCondition"
					>
						<span v-if="!showCondition">展开</span>
						<span v-else>收起</span>
						<vab-icon
							class="vab-dropdown"
							:class="{ 'vab-dropdown-active': fold }"
							icon="arrow-up-s-line"
						/>
					</el-button>
				</div>
			</el-header>
			<el-foot v-show="showCondition">
				<vab-query-form-top-panel>
					<el-form
						inline
						label-width="49px"
						:model="queryForm"
						style="margin-top: 5px"
					>
						<el-form-item label="机构" label-width="100px">
							<sc-org-select
								ref="orgselect"
								:props="props"
								:pageId="'orgUserInfo'"
								:userCode="this.$TOOL.data.get('USER_INFO').userCode"
								:selectKeyValue="'OrgCode'"
								v-model="queryList.OrgCodeList"
								@fatherMethod="orgSelectProcess"
							>
							</sc-org-select>
						</el-form-item>
						<el-form-item label="编号" label-width="100px">
							<el-input
								placeholder="---请输入编号---"
								v-model="queryList.Code"
								style="width: 300px" /></el-form-item
						><el-form-item label="姓名" label-width="100px">
							<el-input
								placeholder="---请输入姓名---"
								v-model="queryList.Name"
								style="width: 300px" /></el-form-item
						><el-form-item label="部门" label-width="100px">
							<el-tree-select
								placeholder="---请选择部门---"
								collapse-tags
                        		collapse-tags-tooltip
								style="width: 300px"
								v-model="queryList.DepartCode"
								:data="optionsDepartCode"
								check-strictly
								:render-after-expand="false"
							/> </el-form-item
						><el-form-item label="性别" label-width="100px">
							<el-select
								placeholder="---请输入性别---"
								v-model="queryList.SexCode"
								collapse-tags
								style="width: 300px"
							>
								<el-option
									label="---请选择---"
									value="" />
								<el-option
									v-for="item in optionsSexCode"
									:key="item.value"
									:label="item.label"
									:value="item.value"
								/>
							</el-select> </el-form-item
						><el-form-item label="职务" label-width="100px">
							<el-select
								placeholder="---请输入编码---"
								v-model="queryList.DutyCode"
								collapse-tags
								style="width: 300px"
							>
								<el-option
									label="---请选择---"
									value="" />
								<el-option
									v-for="item in optionsDutyCode"
									:key="item.value"
									:label="item.label"
									:value="item.value"
								/>
							</el-select> </el-form-item
						><el-form-item label="客户经理" label-width="100px"
							><el-select
								placeholder="---请选择---"
								v-model="queryList.IsCustomerMan"
								style="width: 300px"
								><el-option
									label="---请选择---"
									value="" /><el-option
									label="否"
									value="0" /><el-option
									label="是"
									value="1" /></el-select></el-form-item
						><el-form-item label="可点单" label-width="100px"
							><el-select
								placeholder="---请选择状态---"
								v-model="queryList.AllowOrder"
								style="width: 300px"
								><el-option
									label="---请选择---"
									value="" /><el-option
									label="否"
									value="0" /><el-option
									label="是"
									value="1" /></el-select></el-form-item
						><el-form-item label="状态" label-width="100px"
							><el-select
								placeholder="---请选择状态---"
								v-model="queryList.State"
								style="width: 300px"
								><el-option
									label="---请选择---"
									value="" /><el-option
									label="禁用"
									value="0" /><el-option
									label="启用"
									value="1" /></el-select
						></el-form-item>
					</el-form>
				</vab-query-form-top-panel>
			</el-foot>
			<el-main class="nopadding">
				<scTable
					ref="mytable"
					:data="listData"
					:attrList="attrList"
					:valueList="valueList"
					:queryList="queryList"
					:column="columnList"
					:sort-orders="['ascending', 'descending']"
					@selection-change="selectionChange"
					row-key="Code"
					key="Code"
					stripe
					show-summary
					remoteSummary
				>
					<el-table-column
						type="selection"
						width="50"
					></el-table-column>
					<el-table-column
						label="序号"
						prop="rownumber"
						width="50"
						fixed="left"
					>
					</el-table-column>

					<el-table-column
						label="操作"
						fixed="right"
						align="right"
						width="250"
					>
						<template #default="scope">
							<el-button-group>
								<el-button
									text
									type="primary"
									size="small"
									@click="opShow(scope.row, scope.$index)"
									>查看</el-button
								>
								<el-button
									text
									type="primary"
									size="small"
									@click="opEdit(scope.row, scope.$index)"
									:disabled="!editState"
									>编辑</el-button
								>
								<el-popconfirm
									title="确定删除吗？"
									@confirm="opDelete(scope.row, scope.$index)"
								>
									<template #reference>
										<el-button
											text
											type="primary"
											size="small"
											:disabled="!deleteState"
											>删除</el-button
										>
									</template>
								</el-popconfirm>
								<el-button
									text
									type="primary"
									size="small"
									:disabled="!passwordState"
									@click="opPwd(scope.row, scope.$index)"
									>密码</el-button
								>
								<el-button
									text
									type="primary"
									size="small"
									@click="opPurview(scope.row, 0)"
									:disabled="!adminAuthState"
									>后台授权</el-button>
									<el-button
									text
									type="primary"
									size="small"
									@click="opPurview(scope.row, 1)"
									:disabled="!waiterAuthState"
									>手机服务员授权</el-button>
									<el-button
									text
									type="primary"
									size="small"
									:disabled="!pcAuthState"
									@click="opPurview(scope.row, 2)"
									>电脑点单授权</el-button>
							</el-button-group>
						</template>
					</el-table-column>
				</scTable>
			</el-main>
		</el-container>
	</el-container>

	<el-dialog v-model="dialogPwd" title="设置密码" width="800px">
		<el-form :model="userObj" :rules="rules" ref="dialogPwd">
			<el-row
				><el-col
					><el-form-item
						label-width="120px"
						label="新密码"
						prop="newPwd"
						><el-input
							v-model="userObj.newPwd" /></el-form-item></el-col
			></el-row>
			<el-row
				><el-col
					><el-form-item
						label-width="120px"
						label="确认密码"
						prop="newPwd2"
						><el-input
							v-model="userObj.newPwd2" /></el-form-item></el-col
			></el-row>
		</el-form>
		<template #footer>
			<el-button @click="dialogPwd = false">取 消</el-button>
			<el-button type="primary" @click="opSavePwd()">保 存</el-button>
		</template>
	</el-dialog>

	<save-dialog
		v-if="dialogSave" 
		ref="saveDialog"
		@fatherMethod="opBindData"
		@success="handleSuccess"
		@closed="dialogSave = false"
	></save-dialog>

	<purview-dialog
		v-if="dialogPurview"
		ref="purviewDialog"
		@fatherMethod="opBindData"
		@success="handleSuccess"
		@closed="dialogPurview = false"
	></purview-dialog>

	<organize-select
		v-if="dialogShowSelectOrg"
		ref="saveDialogOrg"
		@fatherMethod="opBindData"
		@success="handleSuccess"
		@closed="dialogShowSelectOrg = false"
	></organize-select>
</template>

<script>
import saveDialog from "./save";
import organizeSelect from "./organizeSelect";
import purviewDialog from "./purview";
import publicjs from "@/api/model/publicjs";
import tool from "@/utils/tool";
import { ref, watch } from "vue";
export default {
	name: "userInfo",
	components: {
		saveDialog,
		purviewDialog,
		publicjs,
		organizeSelect,
	},
	watch: {
		groupFilterText(val) {
			this.$refs.tree.filter(val);
		},
	},
	data() {
		return {
			dialogSave: false,
			dialogPwd: false,
			dialogPurview: false,
			showGrouploading: false,
			dialogShowSelectOrg: false,
			groupFilterText: "",
			group: [],
			apiObj: this.$API.system.user.list,
			showCondition: false,
			isShow: true,
			selectionRows: [],
			pkList: ["Code"],
			columnList: [
				{
					label: "机构",
					prop: "OrgName",
					width: "180",
					hide: false,
					fixed: false,
				},
				// {
				// 	label: "品牌",
				// 	prop: "BrandName",
				// 	width: "180",
				// 	hide: false,
				// 	fixed: false,

				// },
				{
					label: "编号",
					prop: "Code",
					width: "100",
					sortable: true,
					hide: false,
					fixed: false,
				},
				{
					label: "姓名",
					prop: "Name",
					width: "120",
					sortable: true,
					hide: false,
					fixed: false,
				},
				{
					label: "部门",
					prop: "DepartName",
					width: "150",
					hide: false,
					fixed: false,
				},
				{
					label: "职位",
					prop: "DutyName",
					width: "150",
					hide: false,
					fixed: false,
				},
				{
					label: "性别",
					prop: "SexName",
					width: "100",
					hide: false,
					fixed: false,
				},
				{
					label: "手机",
					prop: "Mobile",
					width: "180",
					hide: false,
					fixed: false,
				},
				{
					label: "Email",
					prop: "Email",
					width: "180",
					hide: false,
					fixed: false,
				},
				{
					label: "微信",
					prop: "WeChat",
					width: "180",
					hide: false,
					fixed: false,
				},
				{
					label: "出生年月",
					prop: "BirthDate",
					width: "150",
					hide: false,
					fixed: false,
				},
				{
					label: "客户经理",
					prop: "IsCustomerManName",
					width: "150",
					hide: false,
					fixed: false,
				},
				{
					label: "可点单",
					prop: "AllowOrderName",
					width: "150",
					hide: false,
					fixed: false,
				},
				{
					label: "状态",
					prop: "State",
					width: "80",
					hide: false,
					fixed: false,
				},
			],
			attrList: {
				Name: "UserInfo",
				UseDistinct: false,
			},
			valueList: {
				Code: "Code",
				Name: "Name",
				OrgName: "OrgName",
				// BrandName: "BrandName",
				DepartName: "DepartName",
				SexName: "SexName",
				DutyName: "DutyName",
				Mobile: "Mobile",
				Email: "Email",
				WeChat: "WeChat",
				BirthDate: "BirthDate",
				IdNumber: "IdNumber",
				IsCustomerMan: "IsCustomerMan",
				AllowOrder: "AllowOrder",
				State: "State",
			},
			queryList: {
				Code: "",
				Name: "",
				OrgCode: "",
				DepartCode: "",
				SexCode: "",
				DutyCode: "",
				IsCustomerMan: "",
				AllowOrder: "",
				State: "",
				InLocal: "0",
				OrgCodeList:[]
			},
			result: "", // 运行结果
			props1: {
				checkStrictly: true,
				emitPath: false,
			},
			optionsDepartCode: [],
			optionsSexCode: [],
			optionsDutyCode: [],
			orgCode: "",
			orgName: "",
			userObj: {
				userCode: "",
				newPwd: "",
				newPwd2: "",
			},
			//验证规则
			rules: {
				newPwd: [{ required: true, type: "string", message: "请填写" }],
				newPwd2: [
					{ required: true, type: "string", message: "请填写" },
					{
						validator: (rule, value, callback) => {
							if (value !== this.userObj.newPwd) {
								callback(new Error("两次输入密码不一致"));
							} else {
								callback();
							}
						},
					},
				],
			},
			addState: false,
			editState: false,
			editBatchState: false,
			deleteState: false,
			deleteBatchState: false,
			passwordState: false,
			adminAuthState: false,
			pcAuthState: false,
			waiterAuthState: false,
			props: {
				label: "OrgName",
				value: "OrgCode",
			},
			orgCodeList: "",
			orgNameList: "",
		};
	},
	methods: {
		//加载树数据getGroup
		async getTree() {
			// this.showGrouploading = true;
			// var res = await this.$API.system.dept.list.get();
			// // eslint-disable-next-line no-debugger
			// //debugger
			// this.showGrouploading = false;
			// var allNode = { id: "", label: "所有" };
			// res.data.unshift(allNode);
			// this.group = res.data;
			this.showGrouploading = true;
			var head = new publicjs.head();
			//publicjs.initHead(head, "query");
			publicjs.initHead(head, "orgtreenew");
			var ed = new publicjs.entitydata(head);
			var eo = new publicjs.entityobj();
			eo.AttrList = {
				Name: "Organize",
			};
			eo.ValueList = {
				Code: "id",
				Name: "label",
				ParentCode: "parentId",
				State: "State",
			};
			eo.QueryList = { State: "1" };
			eo.OrderList = { Code: "asc" };
			ed.Data.Content.ObjectList.Object.push(eo);
			try {
				var returnValueStr = await this.$API.auth.objProcess.post(ed);
				//alert(returnValueStr)
				var returnValue = JSON.parse(returnValueStr);
				let result = JSON.parse(returnValue.Result.Content);
				console.log(result);
				// eslint-disable-next-line no-debugger
				debugger;
				var allNode = { id: "", label: "所有" };
				result.unshift(allNode);
				this.group = result;
				/*
		this.group = [
		  {
			id: "003001",
			label: "华中区",
			parentId: "0",
			children: [
			  {
				id: "0001",
				label: "XXX集团",
				parentId: "003001",
			  },
			  {
				id: "0002",
				label: "快旺",
				parentId: "003001",
			  },
			  {
				id: "0011",
				label: "大鹏二号店",
				parentId: "003001",
			  },
			],
		  },
		  {
			id: "003002",
			label: "华东区",
			parentId: "0",
			children: [
			  {
				id: "0003",
				label: "罗湖一号店",
				parentId: "003002",
			  },
			  {
				id: "0004",
				label: "宝安二号店",
				parentId: "003002",
			  },
			],
		  },
		  {
			id: "003003",
			label: "华南区",
			parentId: "0",
			children: [
			  {
				id: "0005",
				label: "沙井三号店",
				parentId: "003003",
			  },
			  {
				id: "0006",
				label: "忘忧",
				parentId: "003003",
			  },
			],
		  },
		  {
			id: "003004",
			label: "华西区",
			parentId: "0",
			children: [
			  {
				id: "0007",
				label: "南山一号店",
				parentId: "003004",
			  },
			  {
				id: "0008",
				label: "龙华二号店",
				parentId: "003004",
			  },
			],
		  },
		  {
			id: "003005",
			label: "华北区",
			parentId: "0",
			children: [
			  {
				id: "0009",
				label: "开怀",
				parentId: "003005",
			  },
			  {
				id: "0010",
				label: "双龙一号店",
				parentId: "003005",
			  },
			],
		  },
		];*/
				this.showGrouploading = false;
			} catch (error) {
				this.showGrouploading = false;
				this.$alert(error.message, "提示", { type: "error" });
				return false;
			}
		},
		groupFilterNode(value, data) {
			if (!value) return true;
			return this.data.label.indexOf(value) !== -1;
		},
		//树点击事件
		groupClick(data) {
			// var params = {
			// 	groupId: data.id,
			// };
			// eslint-disable-next-line no-debugger
			debugger;
			if (data.id.length == 4) {
				this.addState = true;
				this.queryList.OrgCode = data.id;
				this.orgCode = data.id;
				this.orgName = data.label;
				this.opBindData();
			} else {
				this.addState = false;
			}
		},
		//添加
		opAdd() {
			// if (this.orgCode == "") {
			// 	this.dialogShowSelectOrg = true;
			// 	// this.$message.error("请选择机构");
			// 	// this.isShow=true;
			// 	// return;
			// }
			this.dialogSave = true;
			this.$nextTick(() => {
				this.$refs.saveDialog.open("Add", this.orgCodeList,this.orgNameList);
			});
		},
		//编辑
		opEdit(row) {
			this.dialogSave = true;
			this.$nextTick(() => {
				this.$refs.saveDialog.open("Edit").setData(row);
			});
		},
		//编辑
		opBatchEdit() {
			this.$router.push({
				path: "/setting/userInfo/batch",
			});
		},
		//密码
		opPwd(row) {
			this.dialogPwd = true;
			this.$nextTick(() => {
				this.userObj.userCode = row.Code;
				console.log(row);
			});
		},
		//授权
		opPurview(row,type) {
			this.dialogPurview = true;
			this.$nextTick(() => {
				this.$refs.purviewDialog.open(type, this.orgCodeList).setData(row);
			});
		},
		//查看
		opShow(row) {
			this.dialogSave = true;
			this.$nextTick(() => {
				this.$refs.saveDialog.open("Show").setData(row);
			});
		},
		//删除
		async opDelete(row) {
			// eslint-disable-next-line no-undef, no-debugger
			//debugger;
			var head = new publicjs.head();
			publicjs.initHead(head, "save");
			var ed = new publicjs.entitydata(head);
			var eo = new publicjs.entityobj();
			eo.AttrList = {
				Name: "UserInfo",
				DoType: "Delete",
				UseDistinct: false,
				OrgCode: "",
				UseBackUp: false,
				UseGroup: false,
			};
			eo.ValueList = {};
			this.pkList.forEach((element) => {
				// eslint-disable-next-line no-undef, no-debugger
				//debugger;
				eo.ValueList[element] = row[element];
			});
			ed.Data.Content.ObjectList.Object.push(eo);
			try {
				var returnValueStr = await this.$API.auth.objProcess.post(ed);
				let returnValue = JSON.parse(returnValueStr);
				if (returnValue.Result.OpFlag == "1") {
					this.$refs.mytable.getData();
					this.$message.success("删除成功");
				} else {
					this.$message.error("操作失败:" + returnValue.Result.OpMsg);
				}
			} catch (error) {
				this.loading = false;
				this.$alert(error.message, "提示", { type: "error" });
				return false;
			}
		},
		//批量删除
		async opBatchDelete() {
			// eslint-disable-next-line no-debugger
			//debugger;
			this.$confirm(
				`确定删除选中的 ${this.selectionRows.length} 项吗？`,
				"提示",
				{
					type: "warning",
				}
			)
				.then(async () => {
					var head = new publicjs.head();
					publicjs.initHead(head, "save");
					var ed = new publicjs.entitydata(head);
					this.selectionRows.forEach((element) => {
						var eo = new publicjs.entityobj();
						eo.AttrList = {
							Name: "UserInfo",
							DoType: "Delete",
							UseDistinct: false,
							OrgCode: "",
							UseBackUp: false,
							UseGroup: false,
						};
						eo.ValueList = {};
						this.pkList.forEach((pkstr) => {
							// eslint-disable-next-line no-undef, no-debugger
							//debugger;
							eo.ValueList[pkstr] = element[pkstr];
						});
						ed.Data.Content.ObjectList.Object.push(eo);
					});

					try {
						var returnValueStr =
							await this.$API.auth.objProcess.post(ed);
						let returnValue = JSON.parse(returnValueStr);
						if (returnValue.Result.OpFlag == "1") {
							this.$refs.mytable.getData();
							this.$message.success("删除成功");
						} else {
							this.$message.error(
								"操作失败:" + returnValue.Result.OpMsg
							);
						}
					} catch (error) {
						this.loading = false;
						this.$alert(error.message, "提示", { type: "error" });
						return false;
					}
				})
				.catch(() => {});
		},
		//表格选择后回调事件
		selectionChange(selection) {
			// eslint-disable-next-line no-debugger
			//debugger;
			this.selectionRows = selection;
		},

		//本地更新数据
		handleSaveSuccess(data, mode) {
			if (mode == "Add") {
				this.$refs.mytable.refresh();
			} else if (mode == "Edit") {
				this.$refs.mytable.refresh();
			}
		},
		async opBindData() {
			this.$refs.mytable.clearSort();
			this.$refs.mytable.getData();
		},
		async opSavePwd() {
			this.$refs.dialogPwd.validate(async (valid) => {
				if (valid) {
					// eslint-disable-next-line no-debugger
					debugger;
					var head = new publicjs.head();
					publicjs.initHead(head, "editpwd");
					var ed = new publicjs.entitydata(head);
					var eo = new publicjs.entityobj();
					eo.AttrList = {
						Name: "UserInfo",
						DoType: "editpwd",
						UseDistinct: false,
						OrgCode: "",
						UseBackUp: false,
						UseGroup: false,
					};
					//eo.ValueList = this.entityObj;
					eo.ValueList = {
						Code: this.userObj.userCode,
						OldPwd: "",
						NewPwd: this.userObj.newPwd,
					};
					ed.Data.Content.ObjectList.Object.push(eo);
					var returnValueStr = await this.$API.auth.objProcess.post(
						ed
					);
					//console.log(returnValueStr);
					//await this.$API.auth.objProcess.post(ed);
					var returnValue = JSON.parse(returnValueStr);
					if (returnValue.Result.OpFlag == "1") {
						this.$message.success("修改成功");
					} else this.$message.error(returnValue.Result.OpMsg);
				} else {
					return false;
				}
			});
		},
		resetSearch() {
			this.queryList.Code = "";
			this.queryList.Name = "";
			this.queryList.DepartCode = "";
			this.queryList.SexCode = "";
			this.queryList.DutyCode = "";
			this.queryList.IsCustomerMan = "";
			this.queryList.AllowOrder = "";
			this.queryList.State = "";
		},
		async initOptions() {
			var head = new publicjs.head();
			publicjs.initHead(head, "getfirstdatasource");
			var ed = new publicjs.entitydata(head);
			var eo = new publicjs.entityobj();
			eo.AttrList = {
				Name: "UserInfo",
				AcceptControl: "DepartCode,SexCode,DutyCode",
				OrgCode: "",
			};
			ed.Data.Content.ObjectList.Object.push(eo);
			try {
				var returnValueStr = await this.$API.auth.objProcess.post(ed);
				var returnValue = JSON.parse(returnValueStr);
				console.log(returnValue.content);
				if (returnValue.Result.OpFlag == "1") {
					var objectList =
						returnValue.Result.Content.ObjectList.Object;
					for (let i = 0; i < objectList.length; i++) {
						let object = objectList[i];
						if (object.Name == "DepartCode") {
							this.optionsDepartCode = object.rows.row; //eval("(" + object.rows + ")");
						} else if (object.Name == "SexCode") {
							this.optionsSexCode = object.rows.row;
						} else if (object.Name == "DutyCode") {
							this.optionsDutyCode = object.rows.row;
						}
					}
				}
			} catch (error) {
				this.loading = false;
				this.$alert(error.message, "提示", { type: "error" });
				return false;
			}
		},
		async orgSelectProcess(rowData) {
			//根据返回机构，设置权限
			// eslint-disable-next-line no-debugger
			debugger; 
			let orgCodeList = "";
			let orgNameList = "";
			if (rowData && rowData.length > 0) {
				if (rowData.length == 1) {
					orgCodeList = rowData[0].OrgCode;
					orgNameList = rowData[0].OrgName;
				} else {
					for (let i = 0; i < rowData.length; i++) {
						orgCodeList += rowData[i].OrgCode + ",";
						orgNameList += rowData[i].OrgName + ";";
					}
				}
			}
			console.log("orgCodeList:" + orgCodeList + ",orgNameList:" + orgNameList);
			//alert(orgCodeList);
			this.orgCodeList = orgCodeList;
			this.orgNameList = orgNameList;
			await this.initPurview(orgCodeList);
			let userCode = tool.data.get("USER_INFO").userCode;
			if (
				userCode == "admin" ||
				userCode == "super" ||
				orgCodeList.length > 0
			) {
				await this.opBindData();
			}
		},
		async initPurview(orgCode = "") {
			orgCode = orgCode.trim(",");
			//this.$refs.orgselect.userCode
			//let orgList=$ref.orgselect.
			// eslint-disable-next-line no-debugger
			//debugger;
			//alert(orgCode);
			let loginUser = this.$TOOL.data.get("USER_INFO").userCode;
			if (orgCode == "" || orgCode.indexOf(",") > 0) {
				this.addState = false;
				this.editState = false;
				this.editBatchState = false;
				this.deleteState = false;
				this.deleteBatchState = false;
				this.passwordState = false;
				this.adminAuthState = false;
				this.pcAuthState = false;
				this.waiterAuthState = false;
			} else {
				var head = new publicjs.head();
				publicjs.initHead(head, "purviewbtn");
				var ed = new publicjs.entitydata(head);
				var eo = new publicjs.entityobj();
				eo.ValueList = {
					PurviewId: "room",
					OrgCode: orgCode,
					UserCode: loginUser.userCode,
				};
				ed.Data.Content.ObjectList.Object.push(eo);
				try {
					var returnValueStr = await this.$API.auth.objProcess.post(
						ed
					);
					var returnValue = JSON.parse(returnValueStr);
					console.log(returnValue.content);
					// eslint-disable-next-line no-debugger
					//debugger;
					if (returnValue.Result.OpFlag == "1") {
						let btnList = returnValue.Result.Content;
						//all,add
						if (btnList == "all") {
							this.addState = true;
							this.editState = true;
							this.editBatchState = true;
							this.deleteState = true;
							this.deleteBatchState = true;
							this.passwordState = true;
							this.adminAuthState = true;
							this.pcAuthState = true;
							this.waiterAuthState = true;
						} else {
							// eslint-disable-next-line no-debugger
							//debugger
							this.addState = btnList.indexOf("add") >= 0;
							this.editState = btnList.indexOf("edit") >= 0;
							this.editBatchState =
								btnList.indexOf("editBatch") >= 0;
							this.deleteState = btnList.indexOf("delete") >= 0;
						}
						console.log(btnList);
					} else {
						this.$message.error(
							"操作失败:" + returnValue.Result.OpMsg
						);
					}
				} catch (error) {
					this.loading = false;
					this.$alert(error.message, "提示", { type: "error" });
					return false;
				}
			}
		},
		
	},
	async mounted() {
		let currentOrgCode = tool.data.get("USER_INFO").currentOrgCode;
		let currentOrgName = tool.data.get("USER_INFO").currentOrgName;
		let currentOrgCodes= currentOrgCode.split(',')
		let currentOrgNames= currentOrgName.split(',')
		currentOrgCodes.map((p,index)=>{
			if(p){this.queryList.OrgCodeList=[...this.queryList.OrgCodeList,{OrgCode:p,OrgName:currentOrgNames[index]}]}
		})
		this.orgCodeList = currentOrgCode;
		this.orgNameList = currentOrgName;
		await this.initPurview(currentOrgCode);
		await this.initOptions();
		await this.opBindData();
	},
};
</script>

<style></style>
